//
//  LDMainTabViewController.swift
//  LDMicroblog
//
//  Created by pro on 15/8/29.
//  Copyright (c) 2015年 pro. All rights reserved.
//

import UIKit

class LDMainTabViewController: UITabBarController {

    @IBOutlet weak var mainTabBar: LDMainTabBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        tabBar.tintColor = UIColor.orangeColor()//按钮选中状态的图片和文字颜色都改变
        
        addChildViewControllers()
        
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    func plusBtnClick() {
   
        println("\(__FUNCTION__)")
    }
    
    private func addChildViewControllers() {
        
        addChildViewController("Home", "Home", "tabbar_home")
        addChildViewController("Message", "Message", "tabbar_message_center")
        addChildViewController("Discover", "Discover", "tabbar_discover")
        addChildViewController("Profile", "Profile", "tabbar_profile")
    }

    private func addChildViewController(sbName: String, _ title: String, _ imgName: String) {
    
        let sb = UIStoryboard(name: sbName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
//        nav.title = title  //nav.tabBarItem.title = title
        nav.topViewController.title = title
        
        nav.tabBarItem.image = UIImage(named: imgName)
        var selImg = UIImage(named: imgName + "_highlighted")
        nav.tabBarItem.selectedImage = selImg//selImg?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        addChildViewController(nav)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
